<template>
  <div class="factory-assessment-box">
    <div class="infoSty">
      <m-iconfont
        classify="m-pc-public"
        icon="m-pc-public_jiesxx"
        color="#4d84ff"
      ></m-iconfont>
      <span>基础信息</span>
    </div>

    <el-form
      ref="dataListBaseInfo"
      :model="dataListBaseInfo"
      :inline="true"
      label-width="100px"
      class="demo-ruleForm"
    >
      <div class="topSty">
        <div>
          <el-form-item label="医院名称:" prop="hospitalName">
            <span>{{ dataListBaseInfo.hospitalName }}</span>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="医院登记号:" prop="hospitalRegisterCode">
            <span>{{ dataListBaseInfo.hospitalRegisterCode }}</span>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="联系电话:" prop="linkPhone">
            <span>{{ dataListBaseInfo.linkPhone }}</span>
          </el-form-item>
        </div>
      </div>
      <div class="topSty">
        <div>
          <el-form-item class="twoSty" label="医院编码:" prop="hospitalCode">
            <span>{{ dataListBaseInfo.hospitalRegisterCode }}</span>
          </el-form-item>
        </div>

        <div>
          <el-form-item class="twoSty" label="法人:" prop="legalPerson">
            <span>{{ dataListBaseInfo.legalPerson }}</span>
          </el-form-item>
        </div>

        <div>
          <el-form-item class="twoSty" label="所在地区:" prop="">
            <span
              >{{ dataListBaseInfo.province }}{{ dataListBaseInfo.city
              }}{{ dataListBaseInfo.county }}</span
            >
          </el-form-item>
        </div>
      </div>

      <div class="topSty">
        <div>
          <el-form-item label="医院简称:" prop="hospitalShortName">
            <span>{{ dataListBaseInfo.hospitalShortName }}</span>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="成立日期:" prop="createDate">
            <span>{{ dataListBaseInfo.createDate }}</span>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="详细地址:" prop="address">
            <span>{{ dataListBaseInfo.address }}</span>
          </el-form-item>
        </div>
      </div>
      <div class="topSty">
        <div>
          <el-form-item label="签约状态:" prop="signingStatus">
            <span>{{ dataListBaseInfo.signingStatus }}</span>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="联系人:" prop="linkMan">
            <span>{{ dataListBaseInfo.linkMan }}</span>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="医院性质:" prop="hospitalNature">
            <span>{{
              dataListBaseInfo.hospitalNature === 1
                ? '公立'
                : dataListBaseInfo.hospitalNature === 2
                ? '民营'
                : '其他'
            }}</span>
          </el-form-item>
        </div>
      </div>
      <el-form-item label="医院简介:" prop="hospitalIntroduction">
        <span>{{ dataListBaseInfo.hospitalIntroduction }}</span>
      </el-form-item>
    </el-form>
    <div class="tab">
      <tabs
        :tabs-arr="TAB_ARR"
        :active-index="auditStatus"
        @returnIndex="onHandletabs"
      >
      </tabs>
    </div>
    <!-- 财务信息 -->
    <div v-if="auditStatus === 0" class="finance">
      <el-form
        ref="ruleForm"
        :model="dataListFinanceInfo"
        :inline="true"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="税务登记号:" prop="taxRegistrationNo">
              <span>{{ dataListFinanceInfo.taxRegistrationNo }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="账户名称:" prop="accountName">
              <span>{{ dataListFinanceInfo.accountName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="对公账户:" prop="publicAccountName">
              <span>{{ dataListFinanceInfo.publicAccountName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="银行名称:" prop="bankAccount">
              <span>{{ dataListFinanceInfo.bankAccount }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="银行名称:" prop="bankAccount">
              <span>{{ dataListFinanceInfo.bankAccount }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开户行名称:" prop="bankName">
              <span>{{ dataListFinanceInfo.bankName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开户行编码:" prop="bankCode">
              <span>{{ dataListFinanceInfo.bankCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="财务负责人:" prop="financialDirector">
              <span>{{ dataListFinanceInfo.financialDirector }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="联系人:" prop="linkMan">
              <span>{{ dataListFinanceInfo.linkMan }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="电话:" prop="linkPhone">
              <span>{{ dataListFinanceInfo.linkPhone }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <!-- 科室信息列表 -->
    <m-editable
      v-if="auditStatus === 1"
      v-loading="table.tableLoading"
      :empty-type="table.resultType"
      :data="table.dataList"
      :columns="COLUMNS_TABLE"
      height="400"
    >
      <template slot="default-address" slot-scope="scope">
        {{
          scope.row.county &&
          scope.row.province +
            scope.row.city +
            scope.row.county +
            scope.row.address
        }}
      </template>
      <template slot="default-action" slot-scope="scope">
        <el-button
          size="mini"
          type="primary"
          plain
          @click.stop="handleEditAddressItem(scope)"
          >编辑</el-button
        >
        <el-button
          size="mini"
          type="primary"
          plain
          @click.stop="toDeleteaDministrative(scope.row)"
          >删除</el-button
        >
      </template>
    </m-editable>

    <!-- 编辑科室弹框 -->
    <Add-offic-dialog
      ref="upload"
      :dialog-visible.sync="addressDialogShow"
      :form-data="currentAddress"
      :loading="submitLoading"
      @done="reSearch"
      @confirmDialog="handleSubmitAddress"
      @closeDialog="handleCancelSubmit"
    />
    <!-- 编辑收件地址 -->
    <consignee-Address-Dialog
      ref="uploadConsignee"
      :dialog-visible.sync="ConsigneeDialogShow"
      :form-data="consigneeCurrentAddress"
      :loading="submitLoading"
      @dones="reSearchConsignee"
      @confirmDialogConsignee="handleSubmitAddressConsignee"
      @closeDialogConsignee="handleCancelSubmitConsignee"
    >
    </consignee-Address-Dialog>
    <!-- 阳采弹框 -->
    <distributionYCDialog
      ref="uploadDistributionYC"
      :dialog-visible.sync="distributionYCDialogShow"
      :form-data="distributionYCCurrentAddress"
      :loading="submitLoading"
      @donees="reSearchDistributionYC"
      @confirmDialogYC="handleSubmitAddressdistributionYC"
      @closeDialogConsignee="handleCancelSubmitYC"
    >
    </distributionYCDialog>

    <!-- 分页模块 -->
    <div v-if="auditStatus === 1" class="footer">
      <el-pagination
        class="pageBox"
        align="right"
        :page-size="page.size"
        :current-page="page.curPage"
        :total="page.total"
        :layout="page.PAGINATION_LAYOUT"
        :page-sizes="page.PAGE_NUMBER"
        @size-change="onPageSizeChange"
        @current-change="onPageCurrentChange"
      />
    </div>
    <!-- 收件地址列表 -->
    <m-editable
      v-if="auditStatus === 2"
      v-loading="table.tableLoading"
      :empty-type="table.resultType"
      :data="table.dataListTwo"
      :columns="COLUMNS_TABLE_SITE"
      height="800"
    >
      <template slot="default-province" slot-scope="scope">
        {{
          scope.row.county &&
          scope.row.province + scope.row.city + scope.row.county
        }}
      </template>
      <template slot="default-action" slot-scope="scope">
        <el-button
          size="mini"
          type="primary"
          plain
          @click.stop="handleEditAddressConsignee(scope)"
          >编辑</el-button
        >
        <el-button
          size="mini"
          type="primary"
          plain
          @click.stop="toDeleteaConsigneeAddress(scope.row)"
          >删除</el-button
        >
      </template>
    </m-editable>
    <div v-if="auditStatus === 2" class="footer">
      <el-pagination
        class="pageBox"
        align="right"
        :page-size="page.size"
        :current-page="page.curPage"
        :total="page.total"
        :layout="page.PAGINATION_LAYOUT"
        :page-sizes="page.PAGE_NUMBER"
        @size-change="onPageSizeChange"
        @current-change="onPageCurrentChange"
      />
    </div>

    <!-- 阳采配送点 -->
    <m-editable
      v-if="auditStatus === 3"
      v-loading="table.tableLoading"
      :empty-type="table.resultType"
      :data="table.dataList_purchase"
      :columns="yangcai"
      height="800"
    >
      <template slot="default-address" slot-scope="scope">
        {{
          scope.row.county &&
          scope.row.province +
            scope.row.city +
            scope.row.county +
            scope.row.address
        }}
      </template>
      <template slot="default-action" slot-scope="scope">
        <el-button
          size="mini"
          type="primary"
          plain
          @click.stop="handleEditAddressdistributionYC(scope)"
          >编辑</el-button
        >
        <el-button
          size="mini"
          type="primary"
          plain
          @click.stop="toDeleteDistributionSitesYC(scope.row)"
          >删除</el-button
        >
      </template>
    </m-editable>
    <div v-if="auditStatus === 3" class="footer">
      <el-pagination
        class="pageBox"
        align="right"
        :page-size="page.size"
        :current-page="page.curPage"
        :total="page.total"
        :layout="page.PAGINATION_LAYOUT"
        :page-sizes="page.PAGE_NUMBER"
        @size-change="onPageSizeChange"
        @current-change="onPageCurrentChange"
      />
    </div>
  </div>
</template>
<script>
/* eslint-disable */

import AddOfficDialog from './examineComponent/addOfficDialog';
import consigneeAddressDialog from './examineComponent/consigneeAddress';
import distributionYCDialog from './examineComponent/distributionYC';

import tabs from '@pc/m-components/m-tabs/index.vue';
import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common';
import { TAB_ARR, COLUMNS_TABLE, COLUMNS_TABLE_SITE, yangcai } from './const';
import {
  hospitalRecordsDetails,
  getDepartmentInformation,
  getConsigneeAddress,
  getDistributionSitesYC,
  deleteDepartmentInformation,
  deleteConsigneeAddress,
  deleteDistributionSitesYC,
  editOffice,
  editConsignee,
  editdistributionYC,
} from '@api/hossyn-order-center';
export default {
  components: {
    tabs,
    AddOfficDialog,
    consigneeAddressDialog,
    distributionYCDialog,
  },
  data() {
    return {
      dataListBaseInfo: {
        hospitalName: '',
        hospitalCode: '',
        hospitalRegisterCode: '',
        hospitalShortName: '',
        legalPerson: '',
        createDate: '',
        linkMan: '',
        linkPhone: '',
        hospitalNature: '',
        province: '',
        city: '',
        county: '',
        address: '',
        hospitalNature: '',
        hospitalIntroduction: '',
      },
      dataListFinanceInfo: {
        taxRegistrationNo: '',
        accountName: '',
        publicAccountName: '',
        bankAccount: '',
        bankName: '',
        bankCode: '',
        financialDirector: '',
        linkMan: '',
        linkPhone: '',
      },
      COLUMNS_TABLE,
      COLUMNS_TABLE_SITE,
      yangcai,
      TAB_ARR,
      ruleForm: {},
      auditStatus: 0,
      table: {
        tableLoading: false,
        resultType: 0,
        dataList: [],
        searchData: {},
        dataListTwo: [],
        dataList_purchase: [],
        dataListFinanceInfo: {},
        dataListBaseInfo: {},
      },
      showAddForm: false,
      confirmLoading: false,
      addForm: {
        status: '',
      },
      options: [
        {
          lable: '有效',
          value: 0,
        },
        {
          lable: '无效',
          value: 1,
        },
      ],
      submitLoading: false,
      addressDialogShow: false,
      ConsigneeDialogShow: false,
      distributionYCDialogShow: false,
      addressList: [],
      consigneeCurrentAddress: {},
      distributionYCCurrentAddress: {},
      currentAddress: {}, // 编辑地址时需要传递进弹窗的当前地址数据，要注意接口返回的数据格式和form中的格式差异处理
      isEdit: false, // 判断当前是新建地址还是编辑地址，用于确定发送的接口请求
      isEditConsignee: false,
      isEditdistributionYC: false,
      rulesAdd: {},
      page: {
        PAGE_NUMBER, // 页码数组
        PAGINATION_LAYOUT, // 页码功能布局
        curPage: 1,
        pageSize: PAGE_NUMBER[0],
        total: 0,
      },
      departCodeData: this.departCodeData,
    };
  },
  created() {
    this.hospitalRecordsDetails();
    this.buttonMethod();
  },
  methods: {
    //  右上角按钮
    buttonMethod() {
      let arr = [
        // { type: 'button', val: '返回', handle: this.back },
        { type: 'primary', val: '编辑', handle: this.toEdit },
      ];
      const btn = {
        type: 'btn',
        arr: arr,
      };
      this.$store.commit('changeLayoutHandle', btn);
    },
    //  跳转编辑页面
    toEdit(row) {
      this.$router.push({
        path: '/distributorSide/archivesManagement/examine/edit',
        query: {
          hospitalCode: this.$route.query.hospitalCode,
        },
      });
    },

    reSearch() {},
    reSearchConsignee() {},
    reSearchDistributionYC() {},
    //  科室确认弹框
    handleSubmitAddress(data) {
      this.submitLoading = true;
      const postData = {
        ...data,
      };
      this.$axios.$post(editOffice, postData).then((res) => {
        this.submitLoading = false;
        this.addressDialogShow = false;
        this.getDepartmentInformationList();
        this.$message({
          message: '编辑成功',
          type: 'success',
        });
      });
    },
    // 收货地址确认
    handleSubmitAddressConsignee(dataConsignee) {
      this.submitLoading = true;
      const postData = {
        ...dataConsignee,
      };
      this.$axios.$post(editConsignee, postData).then((res) => {
        this.submitLoading = false;
        this.ConsigneeDialogShow = false;
        this.getConsigneeAddressList();
        this.$message({
          message: '编辑成功',
          type: 'success',
        });
      });
    },
    // 阳采确认
    handleSubmitAddressdistributionYC(data) {
      this.submitLoading = false;
      const postData = {
        ...data,
      };
      this.$axios
        .$post(editdistributionYC, postData)
        .then((res) => {
          this.distributionYCDialogShow = false;
          this.getDistributionSitesYCList();
          this.$message({
            message: '编辑成功',
            type: 'success',
          });
        })
        .catch((err) => {});
    },

    // 关闭收货地址弹框
    handleCancelSubmitConsignee() {
      this.consigneeCurrentAddress = {};
      this.ConsigneeDialogShow = false;
    },

    // 关闭科室信息弹框
    handleCancelSubmit() {
      this.currentAddress = {};
      this.addressDialogShow = false;
    },
    // 关闭阳采distributionYCDialogShow
    handleCancelSubmitYC() {
      this.distributionYCDialogShow = false;
      this.distributionYCCurrentAddress = {};
    },
    //  切换表头
    onHandletabs(val) {
      this.page.curPage = 1;
      this.auditStatus = val;
      if (val === 1) {
        this.getDepartmentInformationList();
      } else if (val === 2) {
        this.getConsigneeAddressList();
      } else {
        this.getDistributionSitesYCList();
      }
    },
    // 点击分页事件
    onPageSizeChange(size) {
      this.page.pageSize = size;
    },
    onPageCurrentChange(curPage) {
      this.page.curPage = curPage;
    },
    // 医院档案--详情---基本信息和财务信息
    hospitalRecordsDetails() {
      this.tableLoading = true;
      this.$axios({
        url: hospitalRecordsDetails,
        method: 'post',
        data: {
          hospitalCode: this.$route.query.hospitalCode,
          page: this.page.curPage,
          pageSize: this.page.pageSize,
        },
      })
        .then((res) => {
          this.dataListBaseInfo = res.data.payload.baseInfo || {};
          this.dataListFinanceInfo = res.data.payload.financeInfo || {};
          this.page.total = res.data.payload.totalElements;
          if (this.page.total == 0) {
            this.paging = false;
          }
        })
        .finally((err) => {
          this.tableLoading = false;
        });
    },
    // 科室列表
    getDepartmentInformationList() {
      this.tableLoading = true;
      this.$axios({
        url: getDepartmentInformation,
        method: 'post',
        data: {
          // departId
          hospitalCode: this.$route.query.hospitalCode,
          page: this.page.curPage,
          pageSize: this.page.pageSize,
        },
      })
        .then((res) => {
          this.table.dataList = res.data.payload.content;
          this.page.total = res.data.payload.totalElements;
          if (this.page.total == 0) {
            this.paging = false;
          }
        })
        .finally((err) => {
          this.tableLoading = false;
        });
    },
    // 删除科室
    toDeleteaDministrative(row) {
      this.$mdialog({
        type: 'warning',
        message: '此操作将永久删除, 是否继续?',
        'confirm-text': '确定',
        'refuse-text': '取消',
      })
        .then(() => {
          this.tableLoading = true;
          this.$axios({
            url: deleteDepartmentInformation,
            method: 'post',
            data: {
              departId: row.departId,
            },
          }).then((res) => {
            this.getDepartmentInformationList();
          });
        })
        .finally((err) => {
          console.log(err);
        });
    },
    // 编辑科室
    handleEditAddressItem(scope) {
      this.isEdit = true;
      this.currentAddress = scope.row;
      this.addressDialogShow = true;
    },
    // 编辑收货地址
    handleEditAddressConsignee(scope) {
      this.isEditConsignee = true;
      this.consigneeCurrentAddress = scope.row;

      // console.log(this.consigneeCurrentAddress)
      // console.log(this.consigneeCurrentAddress,'this.consigneeCurrentAddress---')

      this.ConsigneeDialogShow = true;
    },
    //  编辑阳采
    handleEditAddressdistributionYC(scope) {
      this.isEditdistributionYC = true;
      this.distributionYCCurrentAddress = scope.row;
      this.distributionYCDialogShow = true;
    },

    // 收件地址
    getConsigneeAddressList() {
      this.tableLoading = true;
      this.$axios({
        url: getConsigneeAddress,
        method: 'post',
        data: {
          // departId
          hospitalCode: this.$route.query.hospitalCode,
          page: this.page.curPage,
          pageSize: this.page.pageSize,
        },
      })
        .then((res) => {
          this.table.dataListTwo = res.data.payload.content;
          this.page.total = res.data.payload.totalElements;
          if (this.page.total == 0) {
            this.paging = false;
          }
        })
        .finally((err) => {
          this.tableLoading = false;
        });
    },
    // 删除收货地址
    toDeleteaConsigneeAddress(row) {
      this.$mdialog({
        type: 'warning',
        message: '此操作将永久删除, 是否继续?',
        'confirm-text': '确定',
        'refuse-text': '取消',
      })
        .then(() => {
          this.tableLoading = true;
          this.$axios({
            url: deleteConsigneeAddress,
            method: 'post',
            data: {
              recevieAddressId: row.recevieAddressId,
            },
          }).then((res) => {
            this.getConsigneeAddressList();
          });
        })
        .finally((err) => {
          console.log(err);
        });
    },
    // 阳采配送点
    getDistributionSitesYCList() {
      this.tableLoading = true;
      this.$axios({
        url: getDistributionSitesYC,
        method: 'post',
        data: {
          // departId
          hospitalCode: this.$route.query.hospitalCode,
          page: this.page.curPage,
          pageSize: this.page.pageSize,
        },
      })
        .then((res) => {
          this.table.dataList_purchase = res.data.payload.content;
          this.page.total = res.data.payload.totalElements;
          if (this.page.total == 0) {
            this.paging = false;
          }
        })
        .finally((err) => {
          this.tableLoading = false;
        });
    },
    // 删除阳采
    toDeleteDistributionSitesYC(row) {
      this.$mdialog({
        type: 'warning',
        message: '此操作将永久删除, 是否继续?',
        'confirm-text': '确定',
        'refuse-text': '取消',
      })
        .then(() => {
          this.tableLoading = true;
          this.$axios({
            url: deleteDistributionSitesYC,
            method: 'post',
            data: {
              distributionId: row.distributionId,
            },
          }).then((res) => {
            this.getDistributionSitesYCList();
          });
        })
        .finally((err) => {
          console.log(err);
        });
    },
  },
};
</script>
<style scoped lang="less">
.factory-assessment-box {
  .infoSty {
    font-size: 18px;
    margin: 18px 10px 18px 10px;
    padding: 0 0 18px 0;
    border-bottom: 1px solid #ccc;
    .btnSty {
      margin: 0 0 0 1100px;
    }
  }
  margin: 0 0 10px 0 !important;
  .factory-assessment-container {
    height: 100%;
    overflow: auto;
    .action-button-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 12px;
      padding: 0 20px;
    }
    .pageBox {
      margin: 0 20px !important;
      padding: 7px 26px 6px 0;
      border: 1px solid @cutOffRuleColor;
      border-top: none;
      border-radius: 0 0 3px 3px;
    }
  }
  .tab {
    margin-bottom: 20px;
  }
  .footer {
    padding: 7px 26px 6px 0;
    border: 1px solid @cutOffRuleColor;
    border-top: none;
    border-radius: 0 0 3px 3px;
  }
  .topSty {
    display: inline-block;
    height: 180px;
    el-form-item {
      width: 80px;
      float: left;
    }
    span {
      display: inline-block;
      width: 190px;
    }
  }
  .butSty {
    display: flex;
    justify-content: space-between;
  }
}
</style>
